/* A texture mapping fragment shader. This shader
   looks up a location in the texture pointed to by 
   the sampler2D variable image, using the interpolated 
   values of the varying texture coordinate as indices.
   The texure color is then modulated by the interpolated
   vertex color (gl_Color).

   This is a fairly simplistic method of texture mapping,
   as it does not take into account issues such as per-
   spective corrected mapping, and does not use system
   variables for (u,v) coordinate support.

   User-side (u,v) coordinate variables are used to 
   demonstrate how custom-defined variables may be
   communicated between shaders and C programs.
*/   

uniform sampler2D image;
uniform int segments;
uniform float n0x, n0y;
uniform float n1x, n1y;
uniform float n2x, n2y;
uniform float n3x, n3y;
uniform float n4x, n4y;
uniform float n5x, n5y;
uniform float n6x, n6y;
uniform float n7x, n7y;

varying float intensity;
varying vec2 fragment_texture_coordinate;
varying vec3 LightDir;
varying vec4 passcolor;

void main(void)
{
	vec2 bump;
	int seg = int (fragment_texture_coordinate.x*float(segments));

	switch ( seg ) {

		case 0:
			bump = vec2 ( n0x, n0y );
			break;

		case 1:
			bump = vec2 ( n1x, n1y );
			break;

		case 2:
			bump = vec2 ( n2x, n2y );
			break;

		case 3:
			bump = vec2 ( n3x, n3y );
			break;

		case 4:
			bump = vec2 ( n4x, n4y );
			break;

		case 5:
			bump = vec2 ( n5x, n5y );
			break;

		case 6:
			bump = vec2 ( n6x, n6y );
			break;

		case 7:
			bump = vec2 ( n7x, n7y );
			break;

		default:
			bump = vec2 ( 1.0, 1.0 );
			break;
	}

	float NdotL = max(dot(vec3(bump,1.0),LightDir),0.0);
	vec3 texColor = vec3(texture2D (image, fragment_texture_coordinate));
	vec3 diffuse = NdotL*passcolor.xyz*texColor;

	gl_FragColor = vec4(diffuse,passcolor.w);
}

